![]() |
PATH![]() |
![]() ![]() |
The Index reference form specifies an object or a location by describing its position with respect to the beginning or end of a container. For related information, see Relative.
className [ index ] integer
integer(st | nd | rd | th ) className
( first | second | third | fourth | fifth | sixth |
seventh | eighth | ninth | tenth ) className
( last | front | back ) className
className is the class identifier of the object being specified.
integer is an integer that describes the position of the object in relation to the beginning of the container (if integer is a positive integer) or the end of the container (if integer is a negative integer).
The forms first , second , and so on are equivalent to the corresponding integer forms (for example, second word is equivalent to 2nd word ). For objects whose index is greater than 10, you can use the forms 12th , 23rd , 101st , etc. (Note that any integer followed by any of the suffixes listed is valid; for example, you can use 11rd to refer to the eleventh object.)
The front form (for example, front window ) is equivalent to className 1 or first className . The last and back forms (for example, last word and back window ) refer to the last object in a container. They are equivalent to className -1 .
Many of the examples in this section require an enclosing Tell statement, targeting the Finder or a word processing application such as AppleWorks, to compile.
Each of the following references specifies the first file on the startup disk:
file 1 of the startup disk
file index 1 of the startup disk
the first file of the startup disk
The following references specify the second word from the beginning of the third paragraph.
word 2 of paragraph 3
2nd word of paragraph 3
second word of paragraph 3
The following references specify the last word in the third paragraph.
word -1 of paragraph 3
last word of paragraph 3
The following reference specifies the next-to-last word in the third paragraph.
word -2 of paragraph 3
The following example contains two references. The first is a reference to the fourth word of the document called Introduction. The second is a reference to the last insertion point in the same document.
tell application "AppleWorks"
move word 4 of text body of document "Introduction" to ¬
end of text body of document "Introduction"
end tell
The following reference specifies the first file in the first folder in the startup disk:
tell application "Finder"
file 1 of folder 1 of startup disk
end tell
An Index can be volatile. Changing some other property of the object may change its index, as well as the index of other like objects. For example, after deleting file 4 in a folder, the file no longer exists. But there may still be a file 4 --the file that was formerly file 5 . After file 4 is deleted, any files with an index higher than 4 will also have a new index. So the object an Index reference refers to can change.
For a unique, persistent reference to an object, you can use the ID reference form, if the application supports it for the object class you are working with. For example, the Finder supports IDs for files, folders, disks, and so on.
A still better way to keep track of a file is to use an alias reference, as described in References to Files.